package com.starlinkdt.api.controller.admin.system;


import com.github.pagehelper.PageHelper;
import com.starlinkdt.common.annotation.Log;
import com.starlinkdt.common.core.controller.BaseController;
import com.starlinkdt.common.core.page.TableDataInfo;
import com.starlinkdt.common.domain.AjaxResult;
import com.starlinkdt.common.domain.system.vo.OaiReqLogVo;
import com.starlinkdt.common.domain.system.entity.OaiReqLog;
import com.starlinkdt.common.enums.BusinessType;
import com.starlinkdt.common.utils.poi.ExcelUtil;
import com.starlinkdt.service.system.IOaiPermService;
import com.starlinkdt.service.system.IOaiReqLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 请求日志控制器
 */
@Api(tags = "OpenApi-请求日志")
@Validated
@RestController
@RequestMapping("/admin/openapi/oaiReqLog")
public class OaiReqLogController extends BaseController {

    @Autowired
    private IOaiReqLogService oaiReqLogService;

    /**
     * 查询请求日志列表
     */
    @ApiOperation("查询请求日志列表")
    @PreAuthorize("@ss.hasPermi('starlinkdt:openapi:oaiReqLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest request, OaiReqLogVo vo) {
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<OaiReqLog> list = oaiReqLogService.list(vo);
        return getDataTable(list);
    }

    /**
     * 根据请求ID查询请求日志
     */
    @ApiOperation("根据请求ID查询请求日志")
    @PreAuthorize("@ss.hasPermi('starlinkdt:openapi:oaiReqLog:detail')")
    @GetMapping("/getById")
    public AjaxResult getById(@RequestParam Long id) {
        OaiReqLog oaiReqLog = oaiReqLogService.getById(id);
        return AjaxResult.success(oaiReqLog);
    }

    /**
     * 新增请求日志
     */
    @ApiOperation("新增请求日志")
    @PreAuthorize("@ss.hasPermi('starlinkdt:openapi:oaiReqLog:add')")
    @Log(title = "请求日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody OaiReqLog oaiReqLog) {
        oaiReqLogService.add(oaiReqLog);
        return AjaxResult.success();
    }


    /**
     * 导出网货平台信息列表
     */
    @ApiOperation("导出请求日志列表")
    @PreAuthorize("@ss.hasPermi('starlinkdt:openapi:oaiReqLog:export')")
    @Log(title = "请求日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaiReqLogVo vo) {
        List<OaiReqLog> list = oaiReqLogService.list(vo);
        ExcelUtil<OaiReqLog> util = new ExcelUtil<OaiReqLog>(OaiReqLog.class);
        util.exportExcel(response, list, "请求日志数据");
    }
}
